import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: "/",
    redirect: "/my",
  },
  {
    path: "/about",
    name: "About",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/About.vue"),
  },
  {
    path: "/course/myCourse",
    name: "我的课程",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/course/myCourse.vue"),
  },
  {
    path: "/course/typeCourse",
    name: "热门与推荐",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/course/typeCourse.vue"),
  },
  {
    path: "/course/courseList",
    name: "课程列表",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/course/courseList.vue"),
  },
  {
    path: "/home/detail4xxqd",
    name: "课程详情(线下签到)",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/home/detail4xxqd.vue"),
  },
  {
    path: "/course/detail4xx",
    name: "课程详情(线下)",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/course/detail4xx.vue"),
  },
  {
    path: "/home/schoolMes",
    name: "学校详情",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/home/schoolMes.vue"),
  },
  {
    path: "/course/detail4xs",
    name: "课程详情(线上)",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/course/detail4xs.vue"),
  },
  {
    path: "/home/zixun",
    name: "资讯列表",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/home/zixun.vue"),
  },
  {
    path: "/home/zixundetail",
    name: "资讯详情",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/home/zixundetail.vue"),
  },
  {
    path: "/course/search",
    name: "搜索课程",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/course/search.vue"),
  },
  {
    path: "/course/search4zx",
    name: "搜索资讯",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/course/search4zx.vue"),
  },
  {
    path: "/course/apply",
    name: "报名",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/course/apply.vue"),
  },
  {
    path: "/selectCampus",
    name: "选择校区",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/home/selectCampus.vue"),
  },
  {
    path: "/my/collect",
    name: "我的收藏",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/collect.vue"),
  },
  {
    path: "/my/study",
    name: "我的学习库",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/study.vue"),
  },
  {
    path: "/my/jifen",
    name: "积分记录",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/jifen.vue"),
  },
  {
    path: "/my/ziliao",
    name: "个人资料",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/ziliao.vue"),
  },
  {
    path: "/my/contribution",
    name: "贡献值记录",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/contribution.vue"),
  },
  {
    path: "/my/info",
    name: "个人资料",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/info.vue"),
  },
  {
    path: "/my/textPage",
    name: "个人资料",
    component: () =>
    import(/* webpackChunkName: "about" */ "./views/my/textPage.vue"),
  },
  {
    path: "/my/saomaqiandao",
    name: "扫码签到",
    component: () =>
      import(/* webpackChunkName: "about" */ "./views/my/saomaqiandao.vue"),
  },
  {
    path: "/wrapper",
    component: () =>
    import(/* webpackChunkName: "about" */ "./components/Wrapper"),
    children: [{
        path: "/home",
        name: "home",
        component: () =>
          import(/* webpackChunkName: "manage" */ "./views/home/home.vue"),
        meta: { isShowTabbar: true }
      }, {
        path: "/course",
        name: "course",
        component: () =>
          import(/* webpackChunkName: "manage" */ "./views/course/course.vue"),
        meta: { isShowTabbar: true }
      }, {
        path: "/message",
        name: "message",
        component: () =>
          import(/* webpackChunkName: "fans" */ "./views/message/message.vue"),
        meta: { isShowTabbar: true }
      }, {
        path: "/my",
        name: "my",
        component: () =>
          import(/* webpackChunkName: "my" */ "./views/my/My.vue"),
        meta: { isShowTabbar: true }
      }
    ],
  },
];

const router = new VueRouter({
  routes
})

const baseurl = "//xxx"
// 解析url参数并获取code
function getUrlParam(name) {   //name为要获取的参数名
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  var rrr = decodeURIComponent(window.location.search);
  var r = rrr.substr(1).match(reg);
  if(r != null) return unescape(r[2]);
  return null; 
}
// 请求微信服务器获取code 方法
function getUserCode() {
  redirectURL = encodeURI((baseurl + window.location.pathname + window.location.search).split('&code')[0]);//获取地址
  const base = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=';
  let state;
  let surl;
  let reserveUrl;
  let appid = "";
  let scope = "1";
  window.location.href =base + appid +'&redirect_uri='+ redirectURL +'&response_type=code&scope='+ scope +  '#wechat_redirect';
}
// 路由守卫
router.beforeEach((to,from,next)=>{
  if(!to.meta.isShowTabbar) {
    document.title = to.name;
  }
  next();
  // if(to.matched.some(res=>res.meta.isLogin)){//判断是否需要登录
  //     if (sessionStorage['username']) {
  //         next();
  //     }else{
  //         next({
  //             path:"/login",
  //             query:{
  //                 redirect:to.fullPath
  //             }
  //         });
  //     }

  // }else{
  //     next()
  // }
});
export default router
